package com.ygo.feihua.adapter;
import android.content.*;
import android.support.v7.widget.*;
import android.view.*;
import java.util.*;
import com.ygo.feihua.*;
import android.widget.*;
import android.view.View.*;
import com.ygo.feihua.util.*;

public class CheckboxAdapter extends RecyclerView.Adapter<CheckboxAdapter.ViewHolder>
{

	private List<Options> data;
	private Context context;
	
	public CheckboxAdapter(Context context,List<Options> data){
		this.context=context;
		this.data=data;
	}
	
	public CheckboxAdapter(Context context,String[] typeList,String[] type16List,long type){
		this.context=context;
		data=new ArrayList<Options>();
		for(int i=0;i<typeList.length;i++){
			Options op=new Options();
			op.setName(typeList[i]);
			op.setName16(type16List[i]);
			long l2=type & Long.valueOf(type16List[i], 16);//把获得的category与各个类型做与运算得出有哪些类型,如果有则等于那个值,没有则为0

			if (l2 == Long.valueOf(type16List[i], 16))
			{
				op.setIsChecked(true);
			}else{
				op.setIsChecked(false);
			}
			data.add(op);
		}
	}
	
	
	@Override
	public CheckboxAdapter.ViewHolder onCreateViewHolder(ViewGroup p1, int p2)
	{
		View v=LayoutInflater.from(p1.getContext()).inflate(R.layout.item_checkbox,p1,false);
		
		// TODO: Implement this method
		return new ViewHolder(v);
	}

	@Override
	public void onBindViewHolder(CheckboxAdapter.ViewHolder vh, final int position)
	{
		
		vh.ic_check.setChecked(data.get(position).isChecked);
		vh.ic_text.setText(data.get(position).getName());
		vh.ic_check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){

				@Override
				public void onCheckedChanged(CompoundButton p1, boolean p2)
				{		
					data.get(position).setIsChecked(p2);			
					// TODO: Implement this method
				}
			});
		vh.v.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					SnackbarUtil.ShortSnackbar(p1,"此类型16进制数为" + data.get(position).name16,SnackbarUtil.blue,SnackbarUtil.white).show();
					// TODO: Implement this method
				}
			});
		// TODO: Implement this method
	}

	@Override
	public int getItemCount()
	{
		// TODO: Implement this method
		return data.size();
	}
	
	public Options getop(int position){
		return data.get(position);
	}
	
	class ViewHolder extends RecyclerView.ViewHolder{
		View v;
		CheckBox ic_check;
		TextView ic_text;
		
		public ViewHolder(View v){
			super(v);
			this.v=v;
			ic_check=(CheckBox) v.findViewById(R.id.ic_check);
			ic_text=(TextView) v.findViewById(R.id.ic_text);
		}
	}
	
	public static class Options{
		private String name;
		private String name16;
		private boolean isChecked;

		public void setName16(String name16)
		{
			this.name16 = name16;
		}

		public String getName16()
		{
			return name16;
		}
		
		public void setIsChecked(boolean isCheck)
		{
			this.isChecked = isCheck;
		}

		public boolean isChecked()
		{
			return isChecked;
		}


		public void setName(String name)
		{
			this.name = name;
		}

		public String getName()
		{
			return name;
		}
	}
	
}
